﻿@using CleanArchitecture.Blazor.Server.UI.Pages.Identity.Forgot
@inherits MudComponentBase
@inject IStringLocalizer<ResetPassword> L
@inject IValidationService Validator
<MudDialog>
    <DialogContent>
        <MudForm Model="@Model" @ref="@_form" Validation="@(Validator.ValidateValue(Model))">
            <MudGrid Spacing="2">
                <MudItem xs="12">
                    <MudTextField Label="@L["User Name"]" For="@(() => Model.UserName)" Value="Model.UserName"></MudTextField>
                </MudItem>
                <MudItem xs="12">
                    <MudTextField InputType="InputType.Password"
                                  Label="@L["New Password"]"
                                  @bind-Value="Model.Password"
                                  For="@(() => Model.Password)"
                                  Variant="Variant.Text"
                                  Required="true"
                                  Class="mt-4" />
                </MudItem>
                <MudItem xs="12">
                    <MudTextField InputType="InputType.Password"
                                  Label="@L["Confirm New Password"]"
                                  @bind-Value="Model.ConfirmPassword"
                                  For="@(() => Model.ConfirmPassword)"
                                  Variant="Variant.Text"
                                  Required="true"
                                  Class="mt-4" />
                </MudItem>
            </MudGrid>
        </MudForm>
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="Cancel">@ConstantString.Cancel</MudButton>
        <MudButton Color="Color.Primary" OnClick="Submit">@ConstantString.Ok</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = default!;

    [EditorRequired][Parameter] public ResetPasswordFormModel Model { get; set; } = default!;

    private MudForm? _form;

    private async Task Submit()
    {
        await _form!.Validate();
        if (_form.IsValid)
        {
            MudDialog.Close(DialogResult.Ok(true));
        }
    }

    private void Cancel()
    {
        MudDialog.Cancel();
    }


}